'use strict';
//把集合collection中相同的元素统计出数量，存入对象数组arr
function count(collection,arr){
  let object = {};
  for(let item of collection){
    if(!object[item]){
      object[item] = {};
      object[item].key = item;
      object[item].count = 1;
    }
    else{
      object[item].count ++;
    }
  }
  for(let item in object){
    arr.push(object[item]);
  }
  return arr;
}
//判断元素ch是否存在于对象object的value属性中
function includes(object,ch){
  for(let valueItem in object){
    for(let item of object[valueItem])
      if(item === ch){
        return true;
      }
  }
  return false;
}
module.exports = function createUpdatedCollection(collectionA, objectB) {
  let result = [];
  count(collectionA,result);
  for(let objItem of result){
    if(includes(objectB,objItem.key)){
      objItem.count=objItem.count-parseInt(objItem.count/3);
    }
  }
  return result;
}
